#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void add() {    
	printf("matrix add operation:\n");
	int row, col;
	printf("rows and cols:\n");
	double matrix_A[100];
	double matrix_B[100];
	scanf("%d %d", &row, &col);
	printf("matrix A:\n");
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)scanf("%lf",&matrix_A[i*col + j]);
	}
	printf("matrix B:\n");
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)scanf("%lf",&matrix_B[i*col + j]);
	}
	double matrix_r[100];
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)matrix_r[i*col + j] = matrix_B[i*col + j] + matrix_A[i*col + j];
	}
	printf("result is :\n");
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)printf("%lf  ", matrix_r[i*col + j]);
		printf("\n");
	}

}

void sub() {
	printf("matrix  sub operation:\n");
	int row, col;
	printf("rows and cols:\n");
	double matrix_A[100];
	double matrix_B[100];
	scanf("%d %d", &row, &col);
	printf("matrix A:\n");
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)scanf("%lf", &matrix_A[i*col + j]);
	}
	printf("matrix B:\n");
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)scanf("%lf", &matrix_B[i*col + j]);
	}
	double matrix_r[100];
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)matrix_r[i*col + j] = 0-matrix_B[i*col + j] +matrix_A[i*col + j];
	}
	printf("result is :\n");
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)printf("%lf  ", matrix_r[i*col + j]);
		printf("\n");
	}

}

void mul() {
	printf("matrix  mul operation:\n");
	int row1, col1;
	int row2, col2;
	printf("rows and cols of A:\n");
	double matrix_A[100];
	double matrix_B[100];
	scanf("%d %d", &row1, &col1);
	printf("matrix A:\n");
	for (int i = 0; i < row1; i++) {
		for (int j = 0; j < col1; j++)scanf("%lf", &matrix_A[i*col1 + j]);
	}
	printf("rows and cols of B:\n");
	scanf("%d %d", &row2, &col2);
	printf("matrix B:\n");
	for (int i = 0; i < row2; i++) {
		for (int j = 0; j < col2; j++)scanf("%lf", &matrix_B[i*col2 + j]);
	}
	double matrix_r[100];
	for (int i = 0; i < row1; i++) {
		for (int j = 0; j < col2; j++) {
			double sum = 0;
				for (int k = 0; k < row2; k++)
				{
					sum += matrix_A[i*col1 + k] * matrix_B[k*col2 + j];
				}
			matrix_r[i*col2 + j] = sum;
		}
	}
	printf("result is :\n");
	for (int i = 0; i < row1; i++) {
		for (int j = 0; j < col2; j++)printf("%lf  ", matrix_r[i*col2 + j]);
		printf("\n");
	}

}
//transposition
void tt() {    
	printf("martix transposition operation:\n");
	int row, col;
	printf("rows and cols:\n");
	double matrix_A[100];
	scanf("%d %d", &row, &col);
	printf("matrix :\n");
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)scanf("%lf", &matrix_A[i*col + j]);
	}
	double matrix_r[100];
	for (int i = 0; i < col; i++) {
		for (int j = 0; j < row; j++)matrix_r[i*col + j] = matrix_A[j*col + i];
	}
	printf("result is :\n");
	for (int i = 0; i < col; i++) {
		for (int j = 0; j < row; j++)printf("%lf  ", matrix_r[i*col + j]);
		printf("\n");
	}
}
//recursion for det
double det_rf(double* martix, int n) {
	if (n == 2)return martix[0] * martix[3] - martix[1] * martix[2];
	else
	{
		int flag = -1;
		double sum = 0;
		int row, col;
		row = col = n - 1;
		for (int i = 0; i < n; i++) {
			int count = 0;
			double temp_matrix[100];
			flag *= -1;
			for (int j = 1; j < n; j++) {
				for (int k = 0; k < n; k++) {
					if (k != i)temp_matrix[count++] = martix[j*n + k];
				}
			}
			sum += flag* martix[i] * det_rf(temp_matrix, n - 1);
		}
		return sum;
	}
}
void det() {
	printf("martix det operation:\n");
	int row, col;
	printf("rows=cols:\n");
	double matrix_A[100];
	scanf("%d", &row);
	printf("martix:\n");
	col = row;
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)scanf("%lf", &matrix_A[i*col + j]);
	}
	double result;
	if (row == 1)result = matrix_A[0];
	else result=det_rf(matrix_A, row);
	printf("result is:\n%lf\n", result);
}
/*
void rank()
{
	printf("martix rank operation:\n");
	int row, col;
	printf("rows and cols:\n");
	double matrix_A[100];
	scanf("%d %d", &row, &col);
	printf("matrix :\n");
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++)scanf("%lf", &matrix_A[i*col + j]);
	}
}
*/
int main()
{
	//add();
	//sub();
	//mul();
	//tt();
	//det();
	system("pause");
	return 0;
}